package com.shujia.filter;

import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;

import java.util.List;

public class ResultUtil {
    public static void printRes(Result result){
        List<Cell> cells = result.listCells();
        String rowKey = Bytes.toString(result.getRow());
        System.out.print(rowKey+"\t");
        for (Cell cell : cells) {
//                cell.getValueArray()
            // 通过CellUtil工具类对cell对象中的数据进行取值
            String family = Bytes.toString(CellUtil.cloneFamily(cell));
            String colum = Bytes.toString(CellUtil.cloneQualifier(cell));
            String value = Bytes.toString(CellUtil.cloneValue(cell));
//                System.out.println("family:"+family+"\tcol:"+colum+"\tvalue:"+value);
            // 对于添加的数据是按照 rowKey + 列名称 + 时间戳 进行排序的
            System.out.print(value+"\t");
        }
        System.out.println();
    }

    public static void printRes(Result result,String col){
        List<Cell> cells = result.listCells();
        String rowKey = Bytes.toString(result.getRow());
        System.out.print(rowKey+"\t");
        for (Cell cell : cells) {
//                cell.getValueArray()
            // 通过CellUtil工具类对cell对象中的数据进行取值
            String family = Bytes.toString(CellUtil.cloneFamily(cell));
            String colum = Bytes.toString(CellUtil.cloneQualifier(cell));
            String value = "";
            if (!colum.equals(col)) {
                value = Bytes.toString(CellUtil.cloneValue(cell));
            }else {
                value = Integer.toString(Bytes.toInt(CellUtil.cloneValue(cell)));
            }
//                System.out.println("family:"+family+"\tcol:"+colum+"\tvalue:"+value);
            // 对于添加的数据是按照 rowKey + 列名称 + 时间戳 进行排序的
            System.out.print(value+"\t");
        }
        System.out.println();
    }
}
